﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;
using Microsoft.Phone.Tasks;
using System.Windows.Navigation;
using System.Windows.Media.Imaging;

namespace KOF.Views
{
    public partial class PopupUserControl : UserControl
    {
        string shoeid;
        string titleurl;
        string descurl;
        string imgurl;
        string url;
        public PopupUserControl()
        {
            InitializeComponent();
        }
        // Constructor Gets Parameters 
        public PopupUserControl(string id,string titleurl1,string descurl1,string imgurl1,string url1)
        {
            try
            {
                InitializeComponent();
                shoeid = id;
                titleurl = titleurl1;
                descurl = descurl1;
                imgurl = imgurl1;
                url = url1;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
       
        // Close popup
        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Popup Mypopup = new Popup();
                PopupUserControl Mycontrol = new PopupUserControl();
                Mypopup.Child = Mycontrol;
                Popup newsPop = this.Parent as Popup;

                newsPop.Visibility = System.Windows.Visibility.Collapsed;
                newsPop.IsOpen = false;
               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
       
        // Twitter Share
        private void btnt_Click(object sender, RoutedEventArgs e)
        {
            try
            {

                string strimg = "";
                string kof_links = "";
                string title = "";
                string eventdate = "";
               
                if (shoeid != null && shoeid != "")
                {
                    KOF.Helpers.ReleaseResult rslt = (from itm in (App.Current as App).lstReleaseResult
                                                      where itm.id == shoeid
                                                      select itm).FirstOrDefault();
                    if (rslt != null)
                    {

                        kof_links = rslt.kof_link;
                        title = rslt.title;
                        eventdate = rslt.event_date;
                        if (rslt.iphone_images.Count > 0)
                        {
                            strimg = rslt.iphone_images[0].ToString();
                        }

                    }
                }
                ShareLinkTask shareOnIG = new ShareLinkTask();
                shareOnIG.Title = titleurl;
               
                shareOnIG.Message = titleurl + Environment.NewLine + url + Environment.NewLine + "KicksOnFire.com - Sneaker News & Release Dates http://www.kicksonfire.com/ via @KicksOnFire";
                shareOnIG.LinkUri = new Uri("http://www.kicksonfire.com/", UriKind.Absolute);
                shareOnIG.Show();
                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        //Facebook Share
        private void btnf_Click(object sender, RoutedEventArgs e)
        {
            try
            {

                string strimg = "";
                string kof_links = "";
                string title = "";
                string eventdate = "";
               
                 if (shoeid != null && shoeid != "")
                {
                KOF.Helpers.ReleaseResult rslt = (from itm in (App.Current as App).lstReleaseResult
                                                  where itm.id == shoeid
                                                  select itm).FirstOrDefault();
                if (rslt != null)
                {

                    kof_links = rslt.kof_link;
                    title = rslt.title;
                    eventdate = rslt.event_date;
                }
                    
                }

                 if (imgurl != "")
                 {
                     strimg = imgurl;
                 }
                 else
                 {
                     strimg = "http://app.kicksonfire.com/kofapp/images/Icon-72@2x.png";
                 }

                 string desc;
                 if (descurl != "")
                 {
                     desc = descurl;
                 }
                 else
                 {
                     desc = "KicksOnFire.com is the #1 online sneaker magazine for sneaker news, updates and release dates for brands such as Air Jordans, Nike, Reebok and more.";
                 }
                 ShareLinkTask shareOnIG = new ShareLinkTask();
                 shareOnIG.Title = titleurl;
                 string strMsg = !String.IsNullOrWhiteSpace(kof_links) ? ("-" + Environment.NewLine + kof_links) : string.Empty;
                 shareOnIG.Message = titleurl + " " + Environment.NewLine + strMsg + " " + Environment.NewLine + desc + " KicksOnFire.com - Sneaker News & Release Dates http://www.kicksonfire.com/ via @KicksOnFire";
                 shareOnIG.LinkUri = new Uri(strimg, UriKind.Absolute);
                 shareOnIG.Show();
                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        //Message
        private void btnm_Click(object sender, RoutedEventArgs e)
        {
            try
            {

                    SmsComposeTask smsTask = new SmsComposeTask();
                   
                    smsTask.Body = titleurl + Environment.NewLine + " " + url + Environment.NewLine + " via KicksOnFire.com";
                    smsTask.Show();
               
              
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        //Email
        private void btne_Click(object sender, RoutedEventArgs e)
        {
            try
            {
            
                    EmailComposeTask emailTask = new EmailComposeTask();
                    emailTask.Subject = titleurl;
                    emailTask.Body = titleurl + Environment.NewLine+" " + url + Environment.NewLine+" via KicksOnFire.com";
                    emailTask.Show();
                }
              
            
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
    }
}